from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-05 14:02:33.742282
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 05, Jan, 2023
Time: 14:02:39
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3531
Nobs: 892.000 HQIC: -51.6520
Log likelihood: 11818.0 FPE: 3.07306e-23
AIC: -51.8368 Det(Omega_mle): 2.77968e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295729 0.049078 6.026 0.000
L1.Burgenland 0.105901 0.033771 3.136 0.002
L1.Kärnten -0.106598 0.018113 -5.885 0.000
L1.Niederösterreich 0.213766 0.070827 3.018 0.003
L1.Oberösterreich 0.079524 0.066931 1.188 0.235
L1.Salzburg 0.249837 0.035872 6.965 0.000
L1.Steiermark 0.029428 0.047082 0.625 0.532
L1.Tirol 0.127300 0.038183 3.334 0.001
L1.Vorarlberg -0.059455 0.032876 -1.808 0.071
L1.Wien 0.068597 0.059672 1.150 0.250
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060513 0.100641 0.601 0.548
L1.Burgenland -0.009479 0.069253 -0.137 0.891
L1.Kärnten 0.048885 0.037144 1.316 0.188
L1.Niederösterreich -0.170242 0.145240 -1.172 0.241
L1.Oberösterreich 0.359208 0.137252 2.617 0.009
L1.Salzburg 0.285574 0.073560 3.882 0.000
L1.Steiermark 0.107467 0.096547 1.113 0.266
L1.Tirol 0.320477 0.078299 4.093 0.000
L1.Vorarlberg 0.025518 0.067416 0.379 0.705
L1.Wien -0.022196 0.122365 -0.181 0.856
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201562 0.025594 7.875 0.000
L1.Burgenland 0.090707 0.017612 5.150 0.000
L1.Kärnten -0.008820 0.009446 -0.934 0.350
L1.Niederösterreich 0.267043 0.036936 7.230 0.000
L1.Oberösterreich 0.108521 0.034904 3.109 0.002
L1.Salzburg 0.053117 0.018707 2.839 0.005
L1.Steiermark 0.015704 0.024553 0.640 0.522
L1.Tirol 0.101492 0.019912 5.097 0.000
L1.Vorarlberg 0.058042 0.017145 3.385 0.001
L1.Wien 0.113535 0.031118 3.648 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107470 0.026272 4.091 0.000
L1.Burgenland 0.048283 0.018078 2.671 0.008
L1.Kärnten -0.015884 0.009696 -1.638 0.101
L1.Niederösterreich 0.197601 0.037914 5.212 0.000
L1.Oberösterreich 0.274849 0.035829 7.671 0.000
L1.Salzburg 0.117380 0.019203 6.113 0.000
L1.Steiermark 0.100712 0.025203 3.996 0.000
L1.Tirol 0.123665 0.020439 6.050 0.000
L1.Vorarlberg 0.070846 0.017599 4.026 0.000
L1.Wien -0.025751 0.031943 -0.806 0.420
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134519 0.047151 2.853 0.004
L1.Burgenland -0.053313 0.032445 -1.643 0.100
L1.Kärnten -0.035852 0.017402 -2.060 0.039
L1.Niederösterreich 0.166185 0.068046 2.442 0.015
L1.Oberösterreich 0.129673 0.064303 2.017 0.044
L1.Salzburg 0.290178 0.034463 8.420 0.000
L1.Steiermark 0.034061 0.045233 0.753 0.451
L1.Tirol 0.158317 0.036683 4.316 0.000
L1.Vorarlberg 0.109673 0.031585 3.472 0.001
L1.Wien 0.068103 0.057329 1.188 0.235
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.065053 0.037546 1.733 0.083
L1.Burgenland 0.038198 0.025836 1.478 0.139
L1.Kärnten 0.049659 0.013857 3.584 0.000
L1.Niederösterreich 0.225920 0.054185 4.169 0.000
L1.Oberösterreich 0.264174 0.051205 5.159 0.000
L1.Salzburg 0.059924 0.027443 2.184 0.029
L1.Steiermark -0.006847 0.036019 -0.190 0.849
L1.Tirol 0.158530 0.029211 5.427 0.000
L1.Vorarlberg 0.069064 0.025151 2.746 0.006
L1.Wien 0.077002 0.045651 1.687 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192127 0.045268 4.244 0.000
L1.Burgenland 0.018118 0.031150 0.582 0.561
L1.Kärnten -0.057060 0.016707 -3.415 0.001
L1.Niederösterreich -0.095400 0.065329 -1.460 0.144
L1.Oberösterreich 0.173228 0.061735 2.806 0.005
L1.Salzburg 0.060760 0.033087 1.836 0.066
L1.Steiermark 0.225773 0.043427 5.199 0.000
L1.Tirol 0.478698 0.035219 13.592 0.000
L1.Vorarlberg 0.053253 0.030324 1.756 0.079
L1.Wien -0.047839 0.055039 -0.869 0.385
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153164 0.050884 3.010 0.003
L1.Burgenland -0.000779 0.035014 -0.022 0.982
L1.Kärnten 0.067263 0.018780 3.582 0.000
L1.Niederösterreich 0.202307 0.073434 2.755 0.006
L1.Oberösterreich -0.071193 0.069395 -1.026 0.305
L1.Salzburg 0.220309 0.037192 5.924 0.000
L1.Steiermark 0.107934 0.048815 2.211 0.027
L1.Tirol 0.083644 0.039588 2.113 0.035
L1.Vorarlberg 0.128289 0.034086 3.764 0.000
L1.Wien 0.110205 0.061868 1.781 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357033 0.030178 11.831 0.000
L1.Burgenland 0.008471 0.020766 0.408 0.683
L1.Kärnten -0.025129 0.011138 -2.256 0.024
L1.Niederösterreich 0.229765 0.043551 5.276 0.000
L1.Oberösterreich 0.148484 0.041156 3.608 0.000
L1.Salzburg 0.052284 0.022058 2.370 0.018
L1.Steiermark -0.016968 0.028951 -0.586 0.558
L1.Tirol 0.121033 0.023478 5.155 0.000
L1.Vorarlberg 0.074257 0.020215 3.673 0.000
L1.Wien 0.052092 0.036692 1.420 0.156
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039647 0.167019 0.185424 0.172215 0.149747 0.132776 0.069901 0.222714
Kärnten 0.039647 1.000000 0.003445 0.132309 0.027661 0.099650 0.428153 -0.048040 0.102117
Niederösterreich 0.167019 0.003445 1.000000 0.354845 0.177370 0.323276 0.141901 0.196593 0.346049
Oberösterreich 0.185424 0.132309 0.354845 1.000000 0.241130 0.348842 0.192930 0.183293 0.277653
Salzburg 0.172215 0.027661 0.177370 0.241130 1.000000 0.160220 0.145825 0.155738 0.144692
Steiermark 0.149747 0.099650 0.323276 0.348842 0.160220 1.000000 0.171176 0.152168 0.102622
Tirol 0.132776 0.428153 0.141901 0.192930 0.145825 0.171176 1.000000 0.128822 0.170178
Vorarlberg 0.069901 -0.048040 0.196593 0.183293 0.155738 0.152168 0.128822 1.000000 0.024296
Wien 0.222714 0.102117 0.346049 0.277653 0.144692 0.102622 0.170178 0.024296 1.000000